from time import sleep
from selenium import webdriver

# 打开浏览器-创建浏览器对象
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By

# 打开浏览器
driver = webdriver.Chrome(executable_path='chromedriver.exe')

# 输入访问地址（URL）
url = r"C:\Users\61783\PycharmProjects\pythonProject\drop.html"
driver.get(url)
# driver = webdriver.Chrome()

# 放大浏览器
driver.maximize_window()

# 实例化并获取ActionChains类
action = ActionChains(driver)

# 获取源元素
source = driver.find_element_by_css_selector("#div1")

# 获取目标元素
target = driver.find_element_by_css_selector("#div2")
sleep(3)
action.drag_and_drop(source, target).perform()

# 扩展 通过坐标偏移量执行
sleep(3)
action.drag_and_drop_by_offset(source, xoffset=300, yoffset=300).perform()

# 间隔3秒，关关闭浏览
sleep(3)

# 退出浏览器
driver.close()